package cn.zy.company.service;

import cn.zy.company.dao.WorkDao;
import cn.zy.company.entity.PageObj;
import cn.zy.company.entity.Work;

import java.util.List;

public class WorkService {
  WorkDao workDao=new WorkDao();
    public void add(Work work) throws Exception {
       workDao.add(work);
    }
    public void delete(Integer id) throws Exception {
        workDao.delete(id);
    }
    public void update(Work work) throws Exception {
       workDao.update(work);
    }
    public Work findById(Integer id) throws Exception {
        return workDao.findById(id);
    }

    public List<Work> findAll() throws Exception {
        return workDao.findAll();
    }
    public PageObj<Work> findAll(PageObj<Work> page) throws Exception {
        List<Work> all = workDao.findAll(page.getPage(), page.getSize());
        page.setList(all);
        long l = workDao.countAll();
        page.setCount(l);
        Integer size = page.getSize();
        long l1 = l % size != 0 ? (l / size + 1) : (l / size);
        page.setPageCount((int) l1);
        return page;
    }
}
